package com.lindroy.androidplayer.ui.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lindroy.androidplayer.R
import com.lindroy.androidplayer.logic.model.ProjectItemResp
import com.lindroy.androidplayer.logic.model.WXArticleResp

/**
 * @author Lin
 * @date 2021/4/25
 * @function 公众号文章适配器
 */
class WxArticleAdapter : BaseQuickAdapter<WXArticleResp, BaseViewHolder>(R.layout.wx_article_item){
    private var collectListener: ((collect: Boolean, id: Int) -> Unit)? = null

    private var itemClickListener: ((item: WXArticleResp) -> Unit)? = null

    override fun convert(holder: BaseViewHolder, item: WXArticleResp) {
        holder.setText(R.id.tvTitle, item.title)
            .setText(R.id.tvDate, item.niceDate)
            .setText(R.id.tvAuthor, item.author)
            .setText(R.id.tvChapter, item.superChapterName)
            .setImageResource(R.id.ivCollect,item.collectedIconId)
        holder.getView<ImageView>(R.id.ivCollect).also {
            it.setImageResource(item.collectedIconId)
            it.setOnClickListener {
                collectListener?.invoke(item.collect, item.id)
            }
        }
        holder.itemView.setOnClickListener {
            itemClickListener?.invoke(item)
        }
    }
    /**
     * 收藏按钮点击监听
     */
    fun setOnCollectClickListener(call: (collect: Boolean, id: Int) -> Unit) {
        collectListener = call
    }

    /**
     * Item点击事件
     */
    fun setOnItemClickListener(callback: (item: WXArticleResp) -> Unit) {
        itemClickListener = callback
    }

}